﻿using System.Collections.Generic;
using MvcContrib;
using MvcContrib.PortableAreas;
using Tamias.BasicCmsPortableArea.Messages;

namespace Tamias.BasicCmsPortableArea.Domain
{
    public class ContentItemService : IContentItemService
    {
        public ContentItem Get(string group, string name)
        {
            var message = new GetContentItemByGroupAndNameMessage();
            Bus.Send(message);
            return message.Item;
        }

        public ContentItem Get(int contentItemId)
        {
            var message = new GetContentItemByIdMessage();
            message.ContentItemId = contentItemId;
            Bus.Send(message);
            return message.Item;
        }

        public List<ContentItem> GetList(int groupId)
        {
            var message = new GetContentItemListMessage();
            message.ContentGroupId = groupId;
            Bus.Send(message);
            return message.Items;
        }
        
        public void Save(ContentItem contentItem)
        {
            var message = new SaveContentItemMessage();
            message.Item = contentItem;
            Bus.Send(message);
        }

        public void Delete(int id)
        {
            var message = new DeleteContentItemMessage();
            message.ContentItemId = id;
            Bus.Send(message);
        }
    }
}
